package cn.itzd.utils;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Component;


/**
 * @Author: dada
 * @Version: 1.0
 * @Description:
 */
@Component
public class ServerUrl {
    public String getUrl() {
        HttpServletRequest request = ServletUtils.getRequest();
        return getDomain(request);
    }

    public static String getDomain(HttpServletRequest request) {
        StringBuffer url = request.getRequestURL();
        String contextPath = request.getServletContext().getContextPath();
        return url.delete(url.length() - request.getRequestURI().length(), url.length()).append(contextPath).toString();
    }
}
